Skip to contentSkip to conversation

Change in openvpn[master]: misc: Fix username overflow spilling into password

Openvpn-devel In review Selva Nair (Code Review) via Openvpn-devel 3 participants 9 messages Nov 3 – Nov 5 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): gerrit.1793666730000.I3c8c62c7d90c2b94dd1cd149b4c13b383a2303e9@gerrit.openvpn.net

#1 lore raw

Attention is currently required from: Arne Schwabe.

Hello Arne Schwabe,

I'd like you to do a code review.
Please visit

    https://gerrit.openvpn.net/c/openvpn/+/2096?usp=email

to review the following change.

Change subject: misc: Fix username overflow spilling into password
......................................................................

misc: Fix username overflow spilling into password

Consume the complete username line before reading the password from an auth file or inline credentials. This also fixes an exactly full username buffer leaving its newline to be read as an empty password in auth files.

Existing credential truncation behaviour is unchanged.

Tests: Add regression coverage for long and boundary-length usernames with missing, blank, or supplied passwords in both inlined and external file inputs.

Github: OpenVPN/openvpn#1140

Change-Id I3c8c62c7d90c2b94dd1cd149b4c13b383a2303e9

---
M src/openvpn/misc.c
M tests/unit_tests/openvpn/test_user_pass.c

2 files changed, 65 insertions(+), 0 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/96/2096/1

src/openvpn/misc.c +12 -0
index 304a87e..8c9ad08 100644
@@ -250,6 +250,10 @@
                 if (!(flags & GET_USER_PASS_PASSWORD_ONLY))
                 {
                     buf_parse(&buf, '\n', up->username, USER_PASS_LEN);
+                    /* The password starts on the next line, even if the username was truncated. */
+                    const char *password = strchr(auth_file, '\n');
+                    password = password ? password + 1 : "";
+                    buf_set_read(&buf, (uint8_t *)password, strlen(password) + 1);
                 }
                 buf_parse(&buf, '\n', up->password, USER_PASS_LEN);
 
@@ -283,6 +287,14 @@
                         msg(M_FATAL, "Error reading username from %s authfile: %s", prefix,
                             auth_file);
                     }
+                    if (!strchr(up->username, '\n'))
+                    {
+                        /* Consume the rest of the username line before reading the password. */
+                        int c;
+                        while ((c = fgetc(fp)) != '\n' && c != EOF)
+                        {
+                        }
+                    }
                 }
                 chomp(up->username);
 
tests/unit_tests/openvpn/test_user_pass.c +53 -0

65 lines not on this page · raw message

--
To view, visit https://gerrit.openvpn.net/c/openvpn/+/2096?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: newchange
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I3c8c62c7d90c2b94dd1cd149b4c13b383a2303e9
Gerrit-Change-Number: 2096
Gerrit-PatchSet: 1
Gerrit-Owner: Selva Nair <[email protected]>
Gerrit-Reviewer: Arne Schwabe <[email protected]>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: Arne Schwabe <[email protected]>

_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel

#2 lore raw
In reply to a message not in the archive

Attention is currently required from: Arne Schwabe.

Hello Arne Schwabe,

I'd like you to reexamine a change. Please visit

    https://gerrit.openvpn.net/c/openvpn/+/2096?usp=email

to look at the new patch set (#2).

Change subject: misc: Fix username overflow spilling into password
......................................................................

misc: Fix username overflow spilling into password

Consume the complete username line before reading the password from an auth file or inline credentials. This also fixes an exactly full username buffer leaving its newline to be read as an empty password in auth files.

Existing credential truncation behaviour is unchanged.

Tests: Add regression coverage for long and boundary-length usernames with missing, blank, or supplied passwords in both inlined and external file inputs.

Github: OpenVPN/openvpn#1140

Change-Id I3c8c62c7d90c2b94dd1cd149b4c13b383a2303e9

---
M src/openvpn/misc.c
M tests/unit_tests/openvpn/test_user_pass.c

2 files changed, 65 insertions(+), 0 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/96/2096/2

src/openvpn/misc.c +12 -0
index 304a87e..8c9ad08 100644
@@ -250,6 +250,10 @@
                 if (!(flags & GET_USER_PASS_PASSWORD_ONLY))
                 {
                     buf_parse(&buf, '\n', up->username, USER_PASS_LEN);
+                    /* The password starts on the next line, even if the username was truncated. */
+                    const char *password = strchr(auth_file, '\n');
+                    password = password ? password + 1 : "";
+                    buf_set_read(&buf, (uint8_t *)password, strlen(password) + 1);
                 }
                 buf_parse(&buf, '\n', up->password, USER_PASS_LEN);
 
@@ -283,6 +287,14 @@
                         msg(M_FATAL, "Error reading username from %s authfile: %s", prefix,
                             auth_file);
                     }
+                    if (!strchr(up->username, '\n'))
+                    {
+                        /* Consume the rest of the username line before reading the password. */
+                        int c;
+                        while ((c = fgetc(fp)) != '\n' && c != EOF)
+                        {
+                        }
+                    }
                 }
                 chomp(up->username);
 
tests/unit_tests/openvpn/test_user_pass.c +53 -0

65 lines not on this page · raw message

--
To view, visit https://gerrit.openvpn.net/c/openvpn/+/2096?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I3c8c62c7d90c2b94dd1cd149b4c13b383a2303e9
Gerrit-Change-Number: 2096
Gerrit-PatchSet: 2
Gerrit-Owner: Selva Nair <[email protected]>
Gerrit-Reviewer: Arne Schwabe <[email protected]>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: Arne Schwabe <[email protected]>

_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel

#3 lore raw
In reply to a message not in the archive

Attention is currently required from: Arne Schwabe, Selva Nair.

Răzvan Cojocaru has posted comments on this change by Selva Nair. ( https://gerrit.openvpn.net/c/openvpn/+/2096?usp=email )

Change subject: misc: Fix username overflow spilling into password
......................................................................

Patch Set 2: Code-Review+2

--
To view, visit https://gerrit.openvpn.net/c/openvpn/+/2096?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I3c8c62c7d90c2b94dd1cd149b4c13b383a2303e9
Gerrit-Change-Number: 2096
Gerrit-PatchSet: 2
Gerrit-Owner: Selva Nair <[email protected]>
Gerrit-Reviewer: Arne Schwabe <[email protected]>
Gerrit-Reviewer: Răzvan Cojocaru <[email protected]>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: Selva Nair <[email protected]>
Gerrit-Attention: Arne Schwabe <[email protected]>
Gerrit-Comment-Date: Tue, 03 Nov 2026 08:12:31 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes

_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel

#4 lore raw

PATCH v2 1/1 misc: Fix username overflow spilling into password

In reply to a message not in the archive

From: Selva Nair <[email protected]>

Consume the complete username line before reading the password from an auth file or inline credentials. This also fixes an exactly full username buffer leaving its newline to be read as an empty password in auth files.

Existing credential truncation behaviour is unchanged.

Tests: Add regression coverage for long and boundary-length usernames with missing, blank, or supplied passwords in both inlined and external file inputs.

Github: OpenVPN/openvpn#1140

Change-Id I3c8c62c7d90c2b94dd1cd149b4c13b383a2303e9

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/2096
---

This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master.

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/2096
This mail reflects revision 2 of this Change.

Acked-by according to Gerrit (reflected above):
Razvan Cojocaru <[email protected]>

src/openvpn/misc.c +12 -0
index 304a87e..8c9ad08 100644
@@ -250,6 +250,10 @@
                 if (!(flags & GET_USER_PASS_PASSWORD_ONLY))
                 {
                     buf_parse(&buf, '\n', up->username, USER_PASS_LEN);
+                    /* The password starts on the next line, even if the username was truncated. */
+                    const char *password = strchr(auth_file, '\n');
+                    password = password ? password + 1 : "";
+                    buf_set_read(&buf, (uint8_t *)password, strlen(password) + 1);
                 }
                 buf_parse(&buf, '\n', up->password, USER_PASS_LEN);
 
@@ -283,6 +287,14 @@
                         msg(M_FATAL, "Error reading username from %s authfile: %s", prefix,
                             auth_file);
                     }
+                    if (!strchr(up->username, '\n'))
+                    {
+                        /* Consume the rest of the username line before reading the password. */
+                        int c;
+                        while ((c = fgetc(fp)) != '\n' && c != EOF)
+                        {
+                        }
+                    }
                 }
                 chomp(up->username);
 
tests/unit_tests/openvpn/test_user_pass.c +53 -0

65 lines not on this page · raw message

_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel

Acked-by Razvan Cojocaru on v2 1/1
#5 lore raw

[Openvpn-devel] [PATCH applied] Re: misc: Fix username overflow spilling into password

The moment you look deeply at the user/password code, you'll find dark secrets, it seems... thanks for fixing, and adding unit tests as well.

Tested the master branch on a t_client setup with valid/invalid password cases (file + inline). Nothing overlong, just basic "this must continue working". Works.

Tried to apply this "as is" to 2.7, and "it looks good", but it fails to build the user-pass-testdriver due to missing infrastructure..

CC user_pass_testdriver-test_user_pass.o
test_user_pass.c:373:54: warning: call to undeclared function 'platform_get_tmp_dir'; ISO C99 and later do not support
implicit function declarations [-Wimplicit-function-declaration]
373 | const char *authfile = platform_create_temp_file(platform_get_tmp_dir(), "user_pass", &gc);
| ^
test_user_pass.c:373:54: error: incompatible integer to pointer conversion passing 'int' to parameter of type
'const char *' [-Wint-conversion]

  373 |     const char *authfile = platform_create_temp_file(platform_get_tmp_dir(), "user_pass", &gc);
      |                                                      ^~~~~~~~~~~~~~~~~~~~~~

./../../src/openvpn/platform.h:128:51: note: passing argument to parameter 'directory' here
128 | const char *platform_create_temp_file(const char *directory, const char *prefix,
| ^
1 warning and 1 error generated.

.. so not applying to 2.7 for now. I think it would make sense, but I don't want to just take half of the patch.

Your patch has been applied to the master branch.

commit 4333525868d68593bbdb5c4270f21275d6a35466 (master)

Author: Selva Nair
Date:   Tue Nov 3 09:13:52 2026 +0100

misc: Fix username overflow spilling into password

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/2096
Message-Id: <[email protected]>
URL: https://www.mail-archive.com/[email protected]/msg40555.html

--
kind regards,

Gert Doering

_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel

#6 lore raw

PATCH 1/1 misc: Fix username overflow spilling into password

From: Selva Nair <[email protected]>

Consume the complete username line before reading the password from an auth file or inline credentials. This also fixes an exactly full username buffer leaving its newline to be read as an empty password in auth files.

Existing credential truncation behaviour is unchanged.

Tests: Add regression coverage for long and boundary-length usernames with missing, blank, or supplied passwords in both inlined and external file inputs.

For release/2.7, adapt the test temporary-directory lookup because platform_get_tmp_dir() is only available on master.

Github: OpenVPN/openvpn#1140

Change-Id I3c8c62c7d90c2b94dd1cd149b4c13b383a2303e9
---
 src/openvpn/misc.c                        | 12 +++++
 tests/unit_tests/openvpn/test_user_pass.c | 63 +++++++++++++++++++++++
 2 files changed, 75 insertions(+)
src/openvpn/misc.c +12 -0
index 1a23e13b..a4280cb9 100644
@@ -255,6 +255,10 @@ get_user_pass_cr(struct user_pass *up, const char *auth_file, const char *prefix
                 if (!(flags & GET_USER_PASS_PASSWORD_ONLY))
                 {
                     buf_parse(&buf, '\n', up->username, USER_PASS_LEN);
+                    /* The password starts on the next line, even if the username was truncated. */
+                    const char *password = strchr(auth_file, '\n');
+                    password = password ? password + 1 : "";
+                    buf_set_read(&buf, (uint8_t *)password, strlen(password) + 1);
                 }
                 buf_parse(&buf, '\n', up->password, USER_PASS_LEN);
 
@@ -288,6 +292,14 @@ get_user_pass_cr(struct user_pass *up, const char *auth_file, const char *prefix
                         msg(M_FATAL, "Error reading username from %s authfile: %s", prefix,
                             auth_file);
                     }
+                    if (!strchr(up->username, '\n'))
+                    {
+                        /* Consume the rest of the username line before reading the password. */
+                        int c;
+                        while ((c = fgetc(fp)) != '\n' && c != EOF)
+                        {
+                        }
+                    }
                 }
                 chomp(up->username);
 
tests/unit_tests/openvpn/test_user_pass.c +63 -0

75 lines not on this page · raw message

Signature · 8 lines
2.48.1



_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel
Acked-by on v1 1/1
#7 lore raw

[Openvpn-devel] [PATCH applied] Re: misc: Fix username overflow spilling into password

Thanks. Verified that this is indeed the same patch, just with the temp file name creation logic adapted to what we have in 2.7, and that it passes the test cases.

(Side note: Gerrit can do "push gerrit HEAD:refs/for/release/2.7" to get a 2.7-version marked & tested as such - very magic, this)

Your patch has been applied to the release/2.7 branch.

commit 8013480c7cbf27632fa748e0e710049c9a641a22

Author: Selva Nair
Date:   Wed Nov 4 17:29:56 2026 -0500

misc: Fix username overflow spilling into password

Message-Id: <[email protected]>
URL: https://www.mail-archive.com/[email protected]/msg40725.html

--
kind regards,

Gert Doering

_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel

#8 lore raw
In reply to a message not in the archive

Gert Doering has uploaded a new patch set (#3) to the change originally created by Selva Nair. ( https://gerrit.openvpn.net/c/openvpn/+/2096?usp=email )

The following approvals got outdated and were removed:
Code-Review+2 by Răzvan Cojocaru

Change subject: misc: Fix username overflow spilling into password
......................................................................

misc: Fix username overflow spilling into password

Consume the complete username line before reading the password from an auth file or inline credentials. This also fixes an exactly full username buffer leaving its newline to be read as an empty password in auth files.

Existing credential truncation behaviour is unchanged.

Tests: Add regression coverage for long and boundary-length usernames with missing, blank, or supplied passwords in both inlined and external file inputs.

Github: OpenVPN/openvpn#1140

Change-Id I3c8c62c7d90c2b94dd1cd149b4c13b383a2303e9

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/2096
Message-Id: <[email protected]>
URL: https://www.mail-archive.com/[email protected]/msg40555.html

---
M src/openvpn/misc.c
M tests/unit_tests/openvpn/test_user_pass.c

2 files changed, 65 insertions(+), 0 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/96/2096/3

src/openvpn/misc.c +12 -0
index 304a87e..8c9ad08 100644
@@ -250,6 +250,10 @@
                 if (!(flags & GET_USER_PASS_PASSWORD_ONLY))
                 {
                     buf_parse(&buf, '\n', up->username, USER_PASS_LEN);
+                    /* The password starts on the next line, even if the username was truncated. */
+                    const char *password = strchr(auth_file, '\n');
+                    password = password ? password + 1 : "";
+                    buf_set_read(&buf, (uint8_t *)password, strlen(password) + 1);
                 }
                 buf_parse(&buf, '\n', up->password, USER_PASS_LEN);
 
@@ -283,6 +287,14 @@
                         msg(M_FATAL, "Error reading username from %s authfile: %s", prefix,
                             auth_file);
                     }
+                    if (!strchr(up->username, '\n'))
+                    {
+                        /* Consume the rest of the username line before reading the password. */
+                        int c;
+                        while ((c = fgetc(fp)) != '\n' && c != EOF)
+                        {
+                        }
+                    }
                 }
                 chomp(up->username);
 
tests/unit_tests/openvpn/test_user_pass.c +53 -0

65 lines not on this page · raw message

--
To view, visit https://gerrit.openvpn.net/c/openvpn/+/2096?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I3c8c62c7d90c2b94dd1cd149b4c13b383a2303e9
Gerrit-Change-Number: 2096
Gerrit-PatchSet: 3
Gerrit-Owner: Selva Nair <[email protected]>
Gerrit-Reviewer: Arne Schwabe <[email protected]>
Gerrit-Reviewer: Răzvan Cojocaru <[email protected]>
Gerrit-CC: openvpn-devel <[email protected]>

_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel

#9 lore raw
In reply to a message not in the archive

Gert Doering has submitted this change. ( https://gerrit.openvpn.net/c/openvpn/+/2096?usp=email )

Change subject: misc: Fix username overflow spilling into password
......................................................................

misc: Fix username overflow spilling into password

Consume the complete username line before reading the password from an auth file or inline credentials. This also fixes an exactly full username buffer leaving its newline to be read as an empty password in auth files.

Existing credential truncation behaviour is unchanged.

Tests: Add regression coverage for long and boundary-length usernames with missing, blank, or supplied passwords in both inlined and external file inputs.

Github: OpenVPN/openvpn#1140

Change-Id I3c8c62c7d90c2b94dd1cd149b4c13b383a2303e9

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/2096
Message-Id: <[email protected]>
URL: https://www.mail-archive.com/[email protected]/msg40555.html

---
M src/openvpn/misc.c
M tests/unit_tests/openvpn/test_user_pass.c

2 files changed, 65 insertions(+), 0 deletions(-)
src/openvpn/misc.c +12 -0
index 304a87e..8c9ad08 100644
@@ -250,6 +250,10 @@
                 if (!(flags & GET_USER_PASS_PASSWORD_ONLY))
                 {
                     buf_parse(&buf, '\n', up->username, USER_PASS_LEN);
+                    /* The password starts on the next line, even if the username was truncated. */
+                    const char *password = strchr(auth_file, '\n');
+                    password = password ? password + 1 : "";
+                    buf_set_read(&buf, (uint8_t *)password, strlen(password) + 1);
                 }
                 buf_parse(&buf, '\n', up->password, USER_PASS_LEN);
 
@@ -283,6 +287,14 @@
                         msg(M_FATAL, "Error reading username from %s authfile: %s", prefix,
                             auth_file);
                     }
+                    if (!strchr(up->username, '\n'))
+                    {
+                        /* Consume the rest of the username line before reading the password. */
+                        int c;
+                        while ((c = fgetc(fp)) != '\n' && c != EOF)
+                        {
+                        }
+                    }
                 }
                 chomp(up->username);
 
tests/unit_tests/openvpn/test_user_pass.c +53 -0

65 lines not on this page · raw message

--
To view, visit https://gerrit.openvpn.net/c/openvpn/+/2096?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: merged
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I3c8c62c7d90c2b94dd1cd149b4c13b383a2303e9
Gerrit-Change-Number: 2096
Gerrit-PatchSet: 3
Gerrit-Owner: Selva Nair <[email protected]>
Gerrit-Reviewer: Arne Schwabe <[email protected]>
Gerrit-Reviewer: Răzvan Cojocaru <[email protected]>
Gerrit-CC: openvpn-devel <[email protected]>

_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel